//
//  SearchToolView.m
//  YCH
//
//  Created by apple on 26/07/2019.
//  Copyright © 2019 KN. All rights reserved.
//

#import "SearchToolView.h"

@interface SearchToolView ()<UISearchBarDelegate>

//
@property (nonatomic, strong) UISearchBar *searchBar;

@end

@implementation SearchToolView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.searchBar];
    
    [_searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
}


-(void)setKeyword:(NSString *)keyword
{
    _keyword = keyword;
    
    self.searchBar.text = _keyword;
}

#pragma mark - UISearchBarDelegate

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar endEditing:YES];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(SearchToolViewDidSearch:)]) {
        [self.delegate SearchToolViewDidSearch:searchBar.text];
    }
}


- (UISearchBar *)searchBar
{
    if (_searchBar == nil) {
        _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, LL_ScreenWidth, 44)];
        _searchBar.tintColor=[UIColor grayColor];
        _searchBar.placeholder = @"请输入搜索内容";
        _searchBar.delegate = self;
    }
    return _searchBar;
}

@end
